package com.miao.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.miao.pojo.Dictionary;
import com.miao.service.IDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * <p>
 * 数据字典 前端控制器
 * </p>
 *
 * @author itcast
 */
//获取数据字典
@Slf4j
@RestController
public class DictionaryController  {

    @Autowired
    private IDictionaryService iDictionaryService;

    @GetMapping("/dictionary/all")
    public List<Dictionary> queryAll() {
        return iDictionaryService.list();
    }

    @GetMapping("/dictionary/code/{code}")
    public Dictionary getByCode(@PathVariable String code) {
        LambdaQueryWrapper<Dictionary> dictionaryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        LambdaQueryWrapper<Dictionary> eq = dictionaryLambdaQueryWrapper.eq(null != code, Dictionary::getCode, code);
        return iDictionaryService.getOne(eq);
    }
}
